<%@page import="entity.Student"%>
<%@page import="manager.StudentMgr"%>
<%@page import="controller.StudentCtrl"%>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <title>Bidding Online System, Merlion University</title>
            <link href="bootstrap-3.0.0-dist/css/bootstrap.css" rel="stylesheet" type="text/css">
                <!-- -->
                <link href="bootstrap-3.0.0-dist/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css">
                    <!-- -->
                    <link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" rel="stylesheet">
                        <link rel="stylesheet" type="text/css" href="css/general.css">
                            <link rel="stylesheet" type="text/css" href="css/bs-example.css">
                                <link href="css/navbar-customized.css" rel="stylesheet" type="text/css">
                                    <script>

                                    </script>
                                    <style id="holderjs-style" type="text/css">.holderjs-fluid {font-size:16px;font-weight:bold;text-align:center;font-family:sans-serif;margin:0}</style></head>

                                    <body style="">

                                        <!-- start of navbar -->
                                        <div class="navbar navbar-default navbar-fixed-top">
                                            <div class="container">
                                                <div class="navbar-header">
                                                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
                                                    <a class="navbar-brand" href="#"><span>Bidding Online System</span></a> </div>
                                                <div class="navbar-collapse collapse">
                                                    <ul class="nav navbar-nav navbar-right">
                                                        <li class="active"><a href="#"><i class="glyphicon glyphicon-th-list"></i> course offerings</a></li>
                                                        <li><a href="#"><i class="glyphicon glyphicon-usd"></i> my current bids</a></li>
                                                        <li><a href="#"><i class="glyphicon glyphicon-check"></i> bidding results</a></li>
                                                        <li><a href="#"><i class="glyphicon glyphicon-shopping-cart"></i> section cart</a></li>
                                                        <li><a href="#"><i class="glyphicon glyphicon-user"></i> logout</a></li>
                                                    </ul>
                                                </div>
                                                <!--/.nav-collapse --> 
                                            </div>
                                        </div>
                                        <!-- end of navbar -->
                                        <%
                                        String error = request.getParameter("errorMsg");
                                                                    if(error == null ){
                                                                        error = "";                                                       
                                                                    }
                                                                    
                                                 %>
                                        <div class="container theme-showcase panel panel-default box-shadow content-box">
                                            <div class="col-md-4 col-md-offset-4">
                                                <div class="page-header">
                                                    <form class="form-signin">
                                                        <h2 class="form-signin-heading">Please sign in</h2>
                                                        <input type="text" class="form-control" placeholder="Email address" autofocus="">
                                                            <input type="password" class="form-control" placeholder="Password">
                                                                <label class="checkbox">
                                                                    <input type="checkbox" value="remember-me"> Remember me
                                                                </label>
                                                                <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
                                                                <%=error%>
                                                                </form>

                                                                </div>
                                                                </div>
                                                                <% 
                                                                    String userId = request.getParameter("Email address");
                                                                    String password = request.getParameter("Password");
                                                                    
                                                                    out.println("testing" + userId);
                                                                    
                                                                    StudentCtrl studentCtrl = new StudentCtrl();
                                                                    
                                                                    if (studentCtrl.authenticateStudent(userId, password)) {
                                                                        
                                                                        StudentMgr studentMgr = new StudentMgr();
                                                                        
                                                                        Student currentStudent = studentMgr.retrieveStudentForUserId(userId);
                                                                                         
                                                                        session.setAttribute("authenticated.user", currentStudent);
                                                                        response.sendRedirect("view-course.jsp");
                                                                        
                                                                    } else {
                                                                %>
                                                                    
                                                                    <input type ="hidden" name="errorMsg" value="Invalid username/password"/>
                                                                    <%
                                                                        out.println("get");
                                                                    
                                                                  }
                                                                %>

                                                                </div>
                                                                </div>
                                                                <!-- /container --> 

                                                                <!-- Bootstrap core JavaScript
                                                                    ================================================== --> 
                                                                <!-- Placed at the end of the document so the pages load faster --> 
                                                                <script src="http://code.jquery.com/jquery.js"></script> 
                                                                <script src="bootstrap-3.0.0-dist/js/bootstrap.min.js"></script> 
                                                                <script src="js/holder.js"></script>


                                                                </body></html>